Fix libpcre2
bindings function pointers
#13090
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The function binding for
pcre2_general_context_create
receives two function pointers.They're typed as void pointers instead of a proc type.
The problem is that at the call site the argument type of one of the callback functions is incorrectly declared as
LibC::Int
, but it should actually beLibC::SizeT
. The function definition mentioned the expected callback type, but it also incorrectly usedInt
.This puts it in the same error class as #13088.
It sometimes worked - including on all platforms where the original PCRE2 implementation was tested, so it wasn't noticed.
Crystal's lib bindings actually has special syntax for function pointers as detailed in https://crystal-lang.org/reference/1.7/syntax_and_semantics/c_bindings/callbacks.html
Function pointers can be expressed as
Proc
type. And when using proc literals at call site, you can even skip the argument types because they're inferred from the function binding.So yay, with this patch the code is safer and more concise.